home *** CD-ROM | disk | FTP | other *** search
- Path: EU.net!sun4nl!ittpub!ittpub!nntp
- Newsgroups: comp.lang.c++
- Subject: Re: static and dynamic classes in C++ ?
- Message-ID: <1996Mar15.134305.1807@ittpub>
- From: wil@ittpub.nl (Wil Evers)
- Date: 15 Mar 96 13:43:05 WET
- References: <3148472F.41C6@informatik.uni-siegen.de>
- Distribution: world
- Nntp-Posting-Host: lintilla
-
- In article <3148472F.41C6@informatik.uni-siegen.de> Runu Knips
- <plrunu@informatik.uni-siegen.de> writes:
-
- > Hi people!
- >
- > 1. Is it possible to declare a class in a way that only
- > dynamic instances of it may be declared ?
-
- Yes. Declare your constructors private, and for each constructor, write a
- corresponding public static member function called `make' or so that
- returns a pointer to a newly allocated object by calling the private
- constructor.
-
- > 2. Is it also possible to declare a class in a way that
- > only static (i.e. stack or data segment) instances may
- > be declared ?
-
- No. You could declare a private operator new() for that class, but that
- will not prevent embedding an object of that class in another
- heap-allocated object.
-
- - Wil
-